#-------------------------------------------------------------------------------
`
Run this function to solve the model
First, solves a model with constant types to get a good initial guess
Second, solves the baseline model for different values of α
`
#-------------------------------------------------------------------------------

#-------------------------------------------------------------------------------
@everywhere begin
### OPTIONS
solve_initial_guess = ifelse(Baseline_α==true, true, false)
avec                = ifelse(Baseline_α==true, -0.028, [-0.034; -0.032; -0.030; -0.029; -0.027; -0.026; -0.024; -0.022] )

using Interpolations, Optim, Roots, JLD, Plots
using Distributions, StatsBase
include("01_Model_Structure.jl");
include("02_Functions.jl");
include("03_Model.jl")
include("04_Main_Iteration_fx.jl");
include("05_Load_Solution.jl");
end # @everywhere
#-------------------------------------------------------------------------------


#-------------------------------------------------------------------------------
#Initial Guess: Solve the constant types case to get an initial guess
#-------------------------------------------------------------------------------
if solve_initial_guess == true
          @everywhere ce = ce_economy_M(nz=2, NQ=1e10, damp=0.95,  model_start=0, save_start=1);
          println("-----------SOLVING FOR INITIAL GUESS------------------------")
          println("------------------------------------------------------------")
          iterate_VF(ce, tol_max=1e-4)
          save(string("model_data/","CE_model_strucutre_Chatterjee.jld"), "ce", ce)
end
#-------------------------------------------------------------------------------

#-------------------------------------------------------------------------------
#Solve the Baseline Model with imperfect information
#-------------------------------------------------------------------------------
for i=1:length(avec)
          @everywhere   a_val = avec[$i]
          @everywhere   ce = ce_economy_M(model_Chatterjee=1, α=a_val); #Loads Constant Type results
          println("-----------SOLVING BASELINE MODEL --------------------------")
          println(ce.α)
          println("------------------------------------------------------------")
          # Solve the model
          iterate_VF(ce, tol_max=5e-4)
          #------------------------------------
          #Save results
          name_file = string("CE_model_structure_alpha_",-1*ce.α,".jld")
          save(string("model_data/",name_file), "ce", ce)
end
#-------------------------------------------------------------------------------
